{layout name="layout"}
{layout name="layout"}
<link href="__PLU__/magic-check/css/magic-check.min.css" rel="stylesheet">
<link href="__PLU__/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<script src="__PLU__/bootstrap-table/bootstrap-table.min.js"></script>
<script src="__PLU__/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
{include file="modals/apis-modal"}
<div class="panel">
    <div class="panel-body">
        <div id="toolbar" class="btn-group mar-rgt">
            <button data-target="#apis-modal" data-toggle="modal" class="btn btn-primary"><i class="ti-plus"></i>新增</button>
            <button class="btn btn-primary" disabled><i class="ti-close"></i>删除</button>
        </div>
        <table id="user-custom-toolbar" class="demo-add-niftycheck" data-toggle="table"
               data-url="{:url('api/apis/get_apis')}"
               data-toolbar="#toolbar"
               data-iconsize="primary"
               data-search="true"
               data-method="post"
               data-show-refresh="true"
               data-show-toggle="false"
               data-show-columns="true"
               data-sort-name="mtime"
               data-sort-order="desc"
               data-page-list="[20,50]"
               data-page-size="20"
               data-striped="true"
               data-query-params-type="limit"
               data-pagination="true" data-side-pagination="server">
            <thead>
                <tr>
                    <th data-field="id" data-searchable="false" data-checkbox="true">ID</th>
                    <th data-field="d_id" data-align="center" data-searchable="false" data-switchable="false" data-visible="false" data-searchable="true">store_id</th>
                    <th data-field="apiname" data-searchable="true" data-align="center">接口名称</th>
                    <th data-field="version" data-searchable="true" data-align="center">版本</th>
                    <th data-field="description" data-searchable="false" data-align="center" data-sortable="true">接口描述</th>
                    <th data-field="URI" data-searchable="false" data-align="center">URI</th>
                    <th data-field="mtime" data-searchable="false" data-align="center">更新时间</th>
                    <th data-field="operation" data-searchable="false" data-switchable="false" data-align="center"  data-formatter="actionFormatter" data-events="actionEvents">操作</th>
                </tr>
            </thead>
        </table>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        var $table = $('#user-custom-toolbar'), $remove = $('#user-delete-row');
        $table.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table', function () {
            $remove.prop('disabled', !$table.bootstrapTable('getSelections').length);
        });
        $table.on('load-success.bs.table',function(field,data){
            if(data.rows.length == 0){

            }
        })
        $table.on('load-error.bs.table',function(status){
            $.niftyNoty({
                type: 'danger',
                icon : 'pli-exclamation icon-2x',
                message : '网络连接失败',
                container : 'floating',
                timer : 1500,
            });
        });
        $remove.click(function () {
            var ids = $.map($table.bootstrapTable('getSelections'), function (row) {
                return row.store_id
            });
            $table.bootstrapTable('remove', {
                field: 'id',
                values: ids
            });
            $remove.prop('disabled', true);
        });
    })
    function actionFormatter(value, row, index) {
        return '<button class="btn btn-xs btn-default" data-target="#apis-modal" data-toggle="modal" data-apiid="'+row.d_id+'" ><i class="ti-slice"></i>修改</button>';
    }
    
</script>

<script type="text/javascript">
    function del_api(e,apiid){
        bootbox.setDefaults({locale:"zh_CN"});
        bootbox.confirm("确定删除吗", function(result) {
            if(result){
                $.ajax({
                    url:"{:url('api/apis/del_api')}",
                    type:"post",
                    data:{"apiid":apiid},
                    dataType:"json",
                    success:function(result){
                        if(result.status == 'success'){
                            $.niftyNoty({
                                type: 'success',
                                icon : 'pli-exclamation icon-2x',
                                message : result.msg,
                                container : 'floating',
                                timer : 1500,
                            });
                            $(e).parents('tr').detach();
                        }else{
                            $.niftyNoty({
                                type: 'warning',
                                icon : 'pli-exclamation icon-2x',
                                message : result.msg,
                                container : 'floating',
                                timer : 1500,
                            });
                        }
                    },
                    error:function(){
                        $.niftyNoty({
                            type: 'danger',
                            icon : 'pli-exclamation icon-2x',
                            message : '网络连接失败',
                            container : 'floating',
                            timer : 1500,
                        });
                    }
                });
            }
        })
    }
</script>